
app.begin(req=>{
    console.log("app.begin",req.pureUrl,req.params)
})

app.get("/miApiListByPage",async function (req,res) {
    $.ajax({
        type: "GET",
        url:"/listByPage",
        contentType: 'application/json;charset=utf-8', //设置请求头信息
        data:req.params, //必须是字符串
        dataType: "json",
        success: function (d) {
            res.send(d.data)
        },
        error: function (result) {
            errorToast(result.msg);
        }
    });
});


app.post("/miApiAdd",async function (req,res) {
    delete req.params.api.id;
    let miApi=req.params.api;
    if(!miApi.parent_id){
        miApi.parent_id=-1;
    }
    $.ajax({
        type: "POST",
        url:"/add",
        contentType: 'application/json;charset=utf-8', //设置请求头信息
        data: JSON.stringify(miApi),
        dataType: "json",
        success: function (d) {
            res.send(d.data)
        },
        error: function (result) {
           console.error(result)
        }
    });
});

app.post("/miApiUpdate",function (req,res) {
    let miApi=req.params.api;
    if(!miApi.parent_id){
        miApi.parent_id=-1;
    }
    $.ajax({
        type: "POST",
        url:"/update",
        contentType: 'application/json;charset=utf-8', //设置请求头信息
        data: JSON.stringify(miApi),
        dataType: "json",
        success: function (d) {
            res.send(d.data)
        },
        error: function (result) {
           console.error(result)
        }
    });
});


app.get("/miApiDelete",async function (req,res) {
    await M.fetchGet("/delete",()=>{
        res.send("ok");
    },req.params)
 
});




